﻿namespace MDXStudio.Tracing
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    internal class UcTracer : UserControl
    {
        private IContainer components;
        private ColumnHeader Duration;
        private ColumnHeader EventClass;
        private ColumnHeader EventSubclass;
        private ListView mListViewTrace;
        private MDXStudio.Tracing.Tracer mTracer;
        private ToolStripButton mTsbClear;
        private ToolStripButton mTsbPause;
        private ToolStripButton mTsbSetting;
        private ToolStripButton mTsbStart;
        private ToolStripButton mTsbStop;
        private TextBox mTxtCurrentEvent;
        private SplitContainer splitContainer1;
        private ColumnHeader TextData;
        private ToolStrip toolStrip1;
        private ToolStripSeparator toolStripSeparator1;

        public UcTracer()
        {
            this.InitializeComponent();
            this.mTracer = new MDXStudio.Tracing.Tracer(this.mListViewTrace);
            this.mTracer.StateChanged += new EventHandler(this.mTracer_StateChanged);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(UcTracer));
            this.toolStrip1 = new ToolStrip();
            this.mTsbSetting = new ToolStripButton();
            this.mTsbClear = new ToolStripButton();
            this.toolStripSeparator1 = new ToolStripSeparator();
            this.mTsbStart = new ToolStripButton();
            this.mTsbPause = new ToolStripButton();
            this.mTsbStop = new ToolStripButton();
            this.splitContainer1 = new SplitContainer();
            this.mListViewTrace = new ListView();
            this.EventClass = new ColumnHeader();
            this.EventSubclass = new ColumnHeader();
            this.Duration = new ColumnHeader();
            this.TextData = new ColumnHeader();
            this.mTxtCurrentEvent = new TextBox();
            this.toolStrip1.SuspendLayout();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            base.SuspendLayout();
            this.toolStrip1.Items.AddRange(new ToolStripItem[] { this.mTsbSetting, this.mTsbClear, this.toolStripSeparator1, this.mTsbStart, this.mTsbPause, this.mTsbStop });
            this.toolStrip1.Location = new Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new Size(0x31a, 0x19);
            this.toolStrip1.TabIndex = 0;
            this.toolStrip1.Text = "toolStrip1";
            this.mTsbSetting.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.mTsbSetting.Image = (Image) manager.GetObject("mTsbSetting.Image");
            this.mTsbSetting.ImageTransparentColor = Color.Magenta;
            this.mTsbSetting.Name = "mTsbSetting";
            this.mTsbSetting.Size = new Size(0x17, 0x16);
            this.mTsbSetting.Text = "Setting";
            this.mTsbSetting.Click += new EventHandler(this.mTsbSetting_Click);
            this.mTsbClear.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.mTsbClear.Image = (Image) manager.GetObject("mTsbClear.Image");
            this.mTsbClear.ImageTransparentColor = Color.Magenta;
            this.mTsbClear.Name = "mTsbClear";
            this.mTsbClear.Size = new Size(0x17, 0x16);
            this.mTsbClear.Text = "Clear";
            this.mTsbClear.Click += new EventHandler(this.mTsbClear_Click);
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new Size(6, 0x19);
            this.mTsbStart.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.mTsbStart.Image = (Image) manager.GetObject("mTsbStart.Image");
            this.mTsbStart.ImageTransparentColor = Color.Magenta;
            this.mTsbStart.Name = "mTsbStart";
            this.mTsbStart.Size = new Size(0x17, 0x16);
            this.mTsbStart.Text = "Start";
            this.mTsbStart.Click += new EventHandler(this.mTsbStart_Click);
            this.mTsbPause.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.mTsbPause.Image = (Image) manager.GetObject("mTsbPause.Image");
            this.mTsbPause.ImageTransparentColor = Color.Magenta;
            this.mTsbPause.Name = "mTsbPause";
            this.mTsbPause.Size = new Size(0x17, 0x16);
            this.mTsbPause.Text = "Pause";
            this.mTsbPause.Click += new EventHandler(this.mTsbPause_Click);
            this.mTsbStop.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.mTsbStop.Image = (Image) manager.GetObject("mTsbStop.Image");
            this.mTsbStop.ImageTransparentColor = Color.Magenta;
            this.mTsbStop.Name = "mTsbStop";
            this.mTsbStop.Size = new Size(0x17, 0x16);
            this.mTsbStop.Text = "Stop";
            this.mTsbStop.Click += new EventHandler(this.mTsbStop_Click);
            this.splitContainer1.Dock = DockStyle.Fill;
            this.splitContainer1.Location = new Point(0, 0x19);
            this.splitContainer1.Name = "splitContainer1";
            this.splitContainer1.Orientation = Orientation.Horizontal;
            this.splitContainer1.Panel1.Controls.Add(this.mListViewTrace);
            this.splitContainer1.Panel2.Controls.Add(this.mTxtCurrentEvent);
            this.splitContainer1.Size = new Size(0x31a, 0x1e6);
            this.splitContainer1.SplitterDistance = 300;
            this.splitContainer1.TabIndex = 2;
            this.mListViewTrace.Columns.AddRange(new ColumnHeader[] { this.EventClass, this.EventSubclass, this.Duration, this.TextData });
            this.mListViewTrace.Dock = DockStyle.Fill;
            this.mListViewTrace.Font = new Font("Lucida Console", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.mListViewTrace.FullRowSelect = true;
            this.mListViewTrace.GridLines = true;
            this.mListViewTrace.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            this.mListViewTrace.LabelWrap = false;
            this.mListViewTrace.Location = new Point(0, 0);
            this.mListViewTrace.Name = "mListViewTrace";
            this.mListViewTrace.Size = new Size(0x31a, 300);
            this.mListViewTrace.TabIndex = 7;
            this.mListViewTrace.UseCompatibleStateImageBehavior = false;
            this.mListViewTrace.View = View.Details;
            this.mListViewTrace.SelectedIndexChanged += new EventHandler(this.mListViewTrace_SelectedIndexChanged);
            this.mListViewTrace.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(this.mListViewTrace_ItemSelectionChanged);
            this.EventClass.Text = "Event Class";
            this.EventClass.Width = 110;
            this.EventSubclass.Text = "Event Subclass";
            this.EventSubclass.Width = 0x75;
            this.Duration.Text = "Duration";
            this.Duration.TextAlign = HorizontalAlignment.Right;
            this.Duration.Width = 0x4d;
            this.TextData.Text = "Text Data";
            this.TextData.Width = 0x131;
            this.mTxtCurrentEvent.Dock = DockStyle.Fill;
            this.mTxtCurrentEvent.Font = new Font("Lucida Console", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.mTxtCurrentEvent.Location = new Point(0, 0);
            this.mTxtCurrentEvent.Multiline = true;
            this.mTxtCurrentEvent.Name = "mTxtCurrentEvent";
            this.mTxtCurrentEvent.ReadOnly = true;
            this.mTxtCurrentEvent.Size = new Size(0x31a, 0xb6);
            this.mTxtCurrentEvent.TabIndex = 0;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.splitContainer1);
            base.Controls.Add(this.toolStrip1);
            base.Name = "UcTracer";
            base.Size = new Size(0x31a, 0x1ff);
            base.Load += new EventHandler(this.UcTracer_Load);
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.Panel2.PerformLayout();
            this.splitContainer1.ResumeLayout(false);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void mListViewTrace_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
        }

        private void mListViewTrace_SelectedIndexChanged(object sender, EventArgs e)
        {
            int num = this.mListViewTrace.Columns.IndexOfKey("TextData");
            if (num >= 0)
            {
                this.mTxtCurrentEvent.Text = this.mListViewTrace.FocusedItem.SubItems[num].Text.Replace("\n", "\r\n");
            }
        }

        private void mTracer_StateChanged(object pSender, EventArgs e)
        {
            switch (this.mTracer.State)
            {
                case eTracerState.Disconnected:
                    this.mTsbPause.Enabled = false;
                    this.mTsbSetting.Enabled = true;
                    this.mTsbStart.Enabled = false;
                    this.mTsbStop.Enabled = false;
                    return;

                case eTracerState.Stopped:
                    this.mTsbPause.Enabled = false;
                    this.mTsbSetting.Enabled = true;
                    this.mTsbStart.Enabled = true;
                    this.mTsbStop.Enabled = false;
                    return;

                case eTracerState.Running:
                    this.mTsbPause.Enabled = true;
                    this.mTsbSetting.Enabled = false;
                    this.mTsbStart.Enabled = false;
                    this.mTsbStop.Enabled = true;
                    return;
            }
            throw new Exception("Unknown tracer state");
        }

        private void mTsbClear_Click(object sender, EventArgs e)
        {
            this.mListViewTrace.Items.Clear();
        }

        private void mTsbPause_Click(object sender, EventArgs e)
        {
            this.mTracer.OnStop();
        }

        private void mTsbSetting_Click(object sender, EventArgs e)
        {
            TracerSetting deepCopy = this.mTracer.Setting.GetDeepCopy();
            if (TracerSettingDialog.StartDialog(base.FindForm(), deepCopy))
            {
                this.mTracer.Setting = deepCopy;
            }
        }

        private void mTsbStart_Click(object sender, EventArgs e)
        {
            this.mTracer.OnStart();
        }

        private void mTsbStop_Click(object sender, EventArgs e)
        {
            this.mTracer.OnStop();
        }

        private void UcTracer_Load(object sender, EventArgs e)
        {
        }

        public MDXStudio.Tracing.Tracer Tracer
        {
            get
            {
                return this.mTracer;
            }
        }
    }
}

